package com.jxb.proxy;

import java.lang.reflect.Method;

import com.jxb.proxy.advisor.BojiaoPointcutAdvisor;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.aop.PointcutAdvisor;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.StaticMethodMatcherPointcut;

import com.jxb.service.UserInterface;
import com.jxb.service.UserService;

/**
 * 类注释
 *
 * @author jiaobo
 * @date Created in 2024/11/24 16:22
 **/
public class ProxyFactoryTest {

    public static void main(String[] args) {
        UserService target = new UserService();
        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setTarget(target);
        proxyFactory.setProxyTargetClass(false);
        // proxyFactory.setInterfaces(UserInterface.class);
//        proxyFactory.addAdvice(new MethodInterceptor() {
//            @Override
//            public Object invoke(MethodInvocation invocation) throws Throwable {
//                System.out.println("before...");
//                Object res = invocation.proceed();
//                System.out.println("after...");
//                return res;
//            }
//        });
        proxyFactory.addAdvisor(new BojiaoPointcutAdvisor());
        UserService userService = (UserService) proxyFactory.getProxy();
        userService.test();
    }

}
